package hibernate.administratorAccount;

import java.util.*;

public class AttendenceInfo implements java.io.Serializable{
	
	private Set records;
	private int timesLate=0;
	private int timesAbsent=0;
	private int timesOnTime=0;
	private int timesAskingForLeave=0;
	private double rateOfLate=1;
	private double rateOfAbsent=1;
	private double rateOnTime=1;
	private double rateAskingForLeaving=1;
	private Employee employee;
	private Long id;
	
	public void setId(Long id){this.id=id;}
	
	public Long getId(){return this.id;}
	
	public void setEmployee(Employee employee){
		this.employee=employee;
	}
	
	public Employee getEmployee(){return employee;}
	
	public void setRecords(Set records){
		this.records=records;
	}
	
	public Set getRecords(){
		return records;
	}
	
	public void setRecordNumber(int recordNumber){}
	
	public int getRecordNumber(){
		return records.size();
	}
	
	public void setTimesLate(int timesLate){
		this.timesLate=timesLate;
	}
	
	public int getTimesLate(){
		calculate();
		return timesLate;
	}
	
	public void setTimesAbsent(int timesAbsent){
		this.timesAbsent=timesAbsent;
	}
	
	public int getTimesAbsent(){
		calculate();
		return timesAbsent;
	}
	
	public void setTimesOnTime(int timesOnTime){
		this.timesOnTime=timesOnTime;
	}
	
	public int getTimesOnTime(){
		calculate();
		return timesOnTime;
	}
	
	public void setTimesAskingForLeave(int timesAskingForLeave){
		this.timesAskingForLeave=timesAskingForLeave;
	}
	
	public int getTimesAskingForLeave(){
		calculate();
		return timesAskingForLeave;
	}
	
	public void setRateOfLate(double rateOfLate){
		this.rateOfLate=rateOfLate;
	}
	
	public double getRateOfLate(){
		calculate();
		return rateOfLate;
	}
	
	public void setRateOfAbsent(double rateOfAbsent){
		this.rateOfAbsent=rateOfAbsent;
	}
	
	public double getRateOfAbsent(){
		calculate();
		return rateOfAbsent;
	}
	
	public void setRateOnTime(double rateOnTime){
		this.rateOnTime=rateOnTime;
	}
	
	public double getRateOnTime(){
		calculate();
		return rateOnTime;
	}
	
	public void setRateAskingForLeaving(double rateAskingForLeaving){
		this.rateAskingForLeaving=rateAskingForLeaving;
	}
	
	public double getRateAskingForLeaving(){
		calculate();
		return rateAskingForLeaving;
	}
	
	private void calculate(){
		AttendenceRecord r;
		
		timesLate=timesAbsent=timesOnTime=timesAskingForLeave=0;
		java.util.Iterator<AttendenceRecord> it=records.iterator();
		while(it.hasNext()){
			r=it.next();
			if(r.getConcreteType()==AttendenceRecord.Type.getLate())
				timesLate++;
			else if(r.getConcreteType()==AttendenceRecord.Type.getAbsent())
				timesAbsent++;
			else if(r.getConcreteType()==AttendenceRecord.Type.getOntime())
				timesOnTime++;
			else if(r.getConcreteType()==AttendenceRecord.Type.getAskingforleave())
				timesAskingForLeave++;
		}
		int total=timesLate+timesAbsent+timesOnTime+timesAskingForLeave+1;
		rateOfLate=(double)timesLate/(double)total;
		rateOfAbsent=timesAbsent/(double)total;
		rateOnTime=(double)timesOnTime/(double)total;
		rateAskingForLeaving=(double)timesAskingForLeave/(double)total;
		
	}
	
	public boolean equals(Object attdInfo){
		if(!(attdInfo instanceof AttendenceInfo))
			return false;
		else return ((AttendenceInfo)attdInfo).id == this.id;
	}
	
}
